<?php

/**
 *  Класс FilleHelper
 *  Помошник для непосредственной работы с Файлами
 * 
 * @author Kosty Ryabichenko <k.ryabichenko@gmail.com>
 * @version 1.0
 */
class GeoHelper {

    public static function getInfo($ip = '', $to = 'utf-8') {


        $ip = ($ip) ? $ip : $_SERVER['REMOTE_ADDR'];
        
        $xml = simplexml_load_file('http://ipgeobase.ru:7020/geo?ip=' . $ip);
        
        if(empty($xml)){
            $xml = simplexml_load_file('http://mail2.bizincom.com/ip.php?ip=' . $ip);
        }
        
        if(empty($xml)){
            $xml = simplexml_load_file('http://paintfxlab.com/geoxml/get.php?ip=' . $ip);
        }

        if ($xml->ip->message) {
            if ($to == 'utf-8') {
                return $xml->ip->message;
            } else {
                if (function_exists('iconv'))
                    return iconv("UTF-8", $to . "//IGNORE", $xml->ip->message);
                else
                    return "The library iconv is not supported by your server";
            }
        }else {
            return $xml;
        }
    }

    public static function getRealIp() {
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }

}

?>
